package com.leaves.javamall.product.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.leaves.javamall.product.dao.AttrAttrgroupRelationDao;
import com.leaves.javamall.product.entity.AttrAttrgroupRelationEntity;
import com.leaves.javamall.product.service.AttrAttrgroupRelationService;
import com.leaves.javamall.product.vo.AttrGroupRelationVo;
import com.leaves.javamall.product.vo.AttrRespVo;
import com.leaves.javamall.product.vo.AttrVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.leaves.javamall.product.entity.AttrEntity;
import com.leaves.javamall.product.service.AttrService;
import com.leaves.common.utils.PageUtils;
import com.leaves.common.utils.R;



/**
 * 商品属性
 *
 * @author leaves
 * @email lxhu.work@gmail.com
 * @date 2020-08-10 16:47:20
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    /**
     * 列表
     */
    @RequestMapping("base/list")
    //@RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils attrlist = attrService.queryPage(params);

        return R.ok().put("page", attrlist);
    }

    //查找baseattr list
    ///product/attr/base/list/0
    @GetMapping("{attrType}/list/{attrId}")
    //@RequiresPermissions("product:attr:list")
    public R listById(@RequestParam Map<String, Object> params, @PathVariable("attrId") Long attrId,@PathVariable("attrType") String type){
        PageUtils page = attrService.queryBaseAttrPage(params,attrId,type);
        return R.ok().put("page",page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
//		AttrEntity attr = attrService.getById(attrId);
        AttrRespVo attrInfo = attrService.getAttrInfo(attrId);
        return R.ok().put("attr", attrInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrVo attr){

        attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrRespVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }


}
